#include <QtGui>
#include <QtCore/QTextCodec>
#include <QTranslator>
#include "gv_setuphomedialog.h"
#include "gv_setupchangepwddiaglog.h"
#include "gv_setuplanguagedialog.h"
#include "gv_setuptimedialog.h"
#include "gv_maintenancehome.h"
#include "gv_maintenancealarmsettingdialog.h"
#include "gv_home.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_MaintenanceAlarmsettingDialog::GV_MaintenanceAlarmsettingDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
    /*ALARMONBUTTON=0,
    ALARMOFFBUTTON,
    ALARMDETAILEDBUTTON,
    ALARM1EBUTTON,
    ALARM2EBUTTON,
    ALARM3EBUTTON*/
    AlarmSettingFrameButtonSelection=ALARMONBUTTON;
    AlarmOnOffSettingFrameButtonSelection=ALARM1EBUTTON;
    Value1eAlarmOn=0;
    Value2eAlarmOn=0;
    Value3eAlarmOn=0;
    Value1eAlarmOff=0;
    Value2eAlarmOff=0;
    Value3eAlarmOff=0;
    ValueAlarmNow = 0;
    AlarmValueLabel->setText(QString::number(Value1eAlarmOn));

    AlarmSettingFrame->show();
    AlarmOnOffSettingFrame->show();
    AlarmSettingDetailedFrame->hide();
    AlarmOnOffSettingFrame->setGeometry(QRect(0,30,480,202));
    AlarmSettingFrame->setGeometry(QRect(0,40,480,232));

    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(AlarmCancelButton,SIGNAL(clicked()),this,SLOT(home()));
    connect(AlarmAcceptButton,SIGNAL(clicked()),this,SLOT(home()));

    connect(DetailedAcceptButton,SIGNAL(clicked()),this,SLOT(home()));
    //connect(DetailedCopyButton,SIGNAL(clicked()),this,SLOT(changelanguage()));
    //connect(DetailedTransmittersSelectionButton,SIGNAL(clicked()),this,SLOT(changelanguage()));
    connect(DetailedCancelButton,SIGNAL(clicked()),this,SLOT(home()));

    connect(DecreaseButton,SIGNAL(clicked()),this,SLOT(DecreaseButtonClicked()));
    connect(IncreaseButton,SIGNAL(clicked()),this,SLOT(IncreaseButtonClicked()));

    connect(AlarmOnSelectButton,SIGNAL(clicked()),this,SLOT(AlarmOnSelectButtonClicked()));
    connect(AlarmOffSelectButton,SIGNAL(clicked()),this,SLOT(AlarmOffSelectButtonClicked()));
    connect(Alarm1eButton,SIGNAL(clicked()),this,SLOT(Alarm1eButtonClicked()));
    connect(Alarm2eButton,SIGNAL(clicked()),this,SLOT(Alarm2eButtonClicked()));
    connect(Alarm3eButton,SIGNAL(clicked()),this,SLOT(Alarm3eButtonClicked()));

    connect(DetailedSelectButton,SIGNAL(clicked()),this,SLOT(AlarmDetailedClicked()));

    timer->start(1000);
}

void GV_MaintenanceAlarmsettingDialog::reloadtext()
{

}
void GV_MaintenanceAlarmsettingDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}
void GV_MaintenanceAlarmsettingDialog::DecreaseButtonClicked()
{
    ValueAlarmNow--;
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog:: IncreaseButtonClicked()
{
    ValueAlarmNow++;
    ValueRefresh();
}

void GV_MaintenanceAlarmsettingDialog::AlarmOnSelectButtonClicked()
{

    AlarmSettingFrameButtonSelection = ALARMONBUTTON;
    AlarmOnOffSettingFrameButtonSelection=ALARM1EBUTTON;
    ValueAlarmNow=Value1eAlarmOn;
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog:: AlarmOffSelectButtonClicked()
{

    AlarmSettingFrameButtonSelection = ALARMOFFBUTTON;
    AlarmOnOffSettingFrameButtonSelection=ALARM1EBUTTON;
    ValueAlarmNow=Value1eAlarmOff;
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog:: Alarm1eButtonClicked()
{    
    AlarmOnOffSettingFrameButtonSelection=ALARM1EBUTTON;
    if(AlarmSettingFrameButtonSelection==ALARMONBUTTON){//alarm on button
        ValueAlarmNow=Value1eAlarmOn;
    }else if(AlarmSettingFrameButtonSelection==ALARMOFFBUTTON){//alarm off button
        ValueAlarmNow=Value1eAlarmOff;
    }
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog:: Alarm2eButtonClicked()
{
    AlarmOnOffSettingFrameButtonSelection=ALARM2EBUTTON;
    if(AlarmSettingFrameButtonSelection==ALARMONBUTTON){//alarm on button
        ValueAlarmNow=Value2eAlarmOn;
    }else if(AlarmSettingFrameButtonSelection==ALARMOFFBUTTON){//alarm off button
        ValueAlarmNow=Value2eAlarmOff;
    }
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog:: Alarm3eButtonClicked()
{
    AlarmOnOffSettingFrameButtonSelection=ALARM3EBUTTON;
    if(AlarmSettingFrameButtonSelection==ALARMONBUTTON){//alarm on button
        ValueAlarmNow=Value3eAlarmOn;
    }else if(AlarmSettingFrameButtonSelection==ALARMOFFBUTTON){//alarm off button
        ValueAlarmNow=Value3eAlarmOff;
    }
    ValueRefresh();
}
void GV_MaintenanceAlarmsettingDialog::ValueRefresh()
{
    AlarmOnOffSettingFrame->show();
    AlarmSettingDetailedFrame->hide();
   /* QMessageBox::about(this,"value","AlarmSettingFrameButtonSelection:" +
                       QString::number(AlarmSettingFrameButtonSelection) +
                       "AlarmOnOffSettingFrameButtonSelection:"+
                       QString::number(AlarmOnOffSettingFrameButtonSelection) +
                       "ValueAlarmNow:"+
                       QString::number(ValueAlarmNow) );*/
    if(AlarmSettingFrameButtonSelection==ALARMONBUTTON)//alarm on button
    {
         if(AlarmOnOffSettingFrameButtonSelection==ALARM1EBUTTON){//1e
             Value1eAlarmOn = ValueAlarmNow;
             AlarmValueLabel->setText(QString::number(Value1eAlarmOn));
         }else if(AlarmOnOffSettingFrameButtonSelection==ALARM2EBUTTON){//2e
             Value2eAlarmOn = ValueAlarmNow;
             AlarmValueLabel->setText(QString::number(Value2eAlarmOn));
         }else if(AlarmOnOffSettingFrameButtonSelection==ALARM3EBUTTON){//3e
             Value3eAlarmOn = ValueAlarmNow;
             AlarmValueLabel->setText(QString::number(Value3eAlarmOn));
         }
    }else if(AlarmSettingFrameButtonSelection==ALARMOFFBUTTON){//alarm off button
        if(AlarmOnOffSettingFrameButtonSelection==ALARM1EBUTTON){//1e
            Value1eAlarmOff = ValueAlarmNow;
            AlarmValueLabel->setText(QString::number(Value1eAlarmOff));
        }else if(AlarmOnOffSettingFrameButtonSelection==ALARM2EBUTTON){//2e
            Value2eAlarmOff = ValueAlarmNow;
            AlarmValueLabel->setText(QString::number(Value2eAlarmOff));
        }else if(AlarmOnOffSettingFrameButtonSelection==ALARM3EBUTTON){//3e
            Value3eAlarmOff = ValueAlarmNow;
            AlarmValueLabel->setText(QString::number(Value3eAlarmOff));
        }
     }else if(AlarmSettingFrameButtonSelection==ALARMDETAILEDBUTTON){//alarm detailed button

     }

}

void GV_MaintenanceAlarmsettingDialog::AlarmDetailedClicked()
{
    AlarmSettingDetailedFrame->setGeometry(QRect(0,40,480,192));
    AlarmSettingDetailedFrame->show();
    AlarmOnOffSettingFrame->hide();

    Value1eAlarmOnLabel->setText(QString::number(Value1eAlarmOn));
    Value2eAlarmOnLabel->setText(QString::number(Value2eAlarmOn));
    Value3eAlarmOnLabel->setText(QString::number(Value3eAlarmOn));

    Value1eAlarmOffLabel->setText(QString::number(Value1eAlarmOff));
    Value2eAlarmOffLabel->setText(QString::number(Value2eAlarmOff));
    Value3eAlarmOffLabel->setText(QString::number(Value3eAlarmOff));
}
void GV_MaintenanceAlarmsettingDialog::home()
{
    QDialog *dialog1 = new GV_MaintenanceHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}






